<?php
declare (strict_types = 1);

namespace app\admin\controller;

use addons\Builder\facade\Builder;
use think\response\Json;

//该文件为自动生成，请按需修改
class TeamLevel extends Base
{
    //所有定义变量均为演示，请根据实际需求更改

    //主键，默认为id
    protected string $pk = 'id';

    //主模型
    protected string $model = '\app\common\model\TeamLevel';


    public function index(): string
    {
        //构建表格数据
        return Builder::Table()
            ->addColumn(['field' => 'id', 'sort' => true, 'title' => 'ID', 'width' => 80])
            ->addColumn(['field' => 'title', 'title' => '名称', 'modify' => '2,input'])
            ->addColumn(['field' => 'team_total', 'title' => '团队业绩', 'modify' => '2,input'])
            ->addColumn(['field' => 'team_reward', 'title' => '团队奖', 'modify' => '2,ratio', 'templet' => '<span>{{(d.team_reward*100).toFixed(2)}}%</span>'])
            ->addColumn(['field' => 'level_reward', 'title' => '平级奖', 'modify' => '2,ratio', 'templet' => '<span>{{(d.level_reward*100).toFixed(2)}}%</span>'])
            ->addColumn(['field' => 'create_time', 'title' => '添加时间'])
            ->addColumn(['field' => 'update_time', 'title' => '更新时间'])
            ->addColumn(['fixed' => 'right', 'title' => '操作', 'align' => 'center', 'toolbar' => '#barDemo', 'width' => 200])
            ->addRightButtons(['edit' => ['size' => '50%']])
            ->addSearch([
                ['title', '等级名称搜索', 'input,Like'],
            ],false)
            ->fetch();
    }

    public function save($param = [], $model = false): Json
    {
        $param = $this->request->post();
        $param['team_reward'] = $param['team_reward'] / 100;
        $param['level_reward'] = $param['level_reward'] / 100;
        return parent::save($param, $model); // TODO: Change the autogenerated stub
    }
}
